/**
 * Copyright (c) 2010 Simple Graph Tools contributors. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * $Id$
 */
package org.sgt.coredef.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.sgt.coredef.Condition;
import org.sgt.coredef.ConditionableObject;
import org.sgt.coredef.ConstrainedObject;
import org.sgt.coredef.Constraint;
import org.sgt.coredef.CoredefPackage;
import org.sgt.coredef.Edge;
import org.sgt.coredef.Node;
import org.sgt.coredef.ProxyEdge;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Proxy Edge</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.sgt.coredef.impl.ProxyEdgeImpl#getPreConditions <em>Pre Conditions</em>}</li>
 *   <li>{@link org.sgt.coredef.impl.ProxyEdgeImpl#getPostConditions <em>Post Conditions</em>}</li>
 *   <li>{@link org.sgt.coredef.impl.ProxyEdgeImpl#getConstraints <em>Constraints</em>}</li>
 *   <li>{@link org.sgt.coredef.impl.ProxyEdgeImpl#getSource <em>Source</em>}</li>
 *   <li>{@link org.sgt.coredef.impl.ProxyEdgeImpl#getDestination <em>Destination</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ProxyEdgeImpl extends ProxyImpl<Edge> implements ProxyEdge {
	/**
	 * The cached value of the '{@link #getPreConditions() <em>Pre Conditions</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPreConditions()
	 * @generated
	 * @ordered
	 */
	protected EList<Condition> preConditions;

	/**
	 * The cached value of the '{@link #getPostConditions() <em>Post Conditions</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPostConditions()
	 * @generated
	 * @ordered
	 */
	protected EList<Condition> postConditions;

	/**
	 * The cached value of the '{@link #getConstraints() <em>Constraints</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getConstraints()
	 * @generated
	 * @ordered
	 */
	protected EList<Constraint> constraints;

	/**
	 * The cached value of the '{@link #getSource() <em>Source</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSource()
	 * @generated
	 * @ordered
	 */
	protected Node source;

	/**
	 * The cached value of the '{@link #getDestination() <em>Destination</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDestination()
	 * @generated
	 * @ordered
	 */
	protected Node destination;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ProxyEdgeImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return CoredefPackage.Literals.PROXY_EDGE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Condition> getPreConditions() {
		if (preConditions == null) {
			preConditions = new EObjectResolvingEList<Condition>(Condition.class, this, CoredefPackage.PROXY_EDGE__PRE_CONDITIONS);
		}
		return preConditions;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Condition> getPostConditions() {
		if (postConditions == null) {
			postConditions = new EObjectResolvingEList<Condition>(Condition.class, this, CoredefPackage.PROXY_EDGE__POST_CONDITIONS);
		}
		return postConditions;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Constraint> getConstraints() {
		if (constraints == null) {
			constraints = new EObjectResolvingEList<Constraint>(Constraint.class, this, CoredefPackage.PROXY_EDGE__CONSTRAINTS);
		}
		return constraints;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Node getSource() {
		if (source != null && source.eIsProxy()) {
			InternalEObject oldSource = (InternalEObject)source;
			source = (Node)eResolveProxy(oldSource);
			if (source != oldSource) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, CoredefPackage.PROXY_EDGE__SOURCE, oldSource, source));
			}
		}
		return source;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Node basicGetSource() {
		return source;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetSource(Node newSource,
			NotificationChain msgs) {
		Node oldSource = source;
		source = newSource;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, CoredefPackage.PROXY_EDGE__SOURCE, oldSource, newSource);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSource(Node newSource) {
		if (newSource != source) {
			NotificationChain msgs = null;
			if (source != null)
				msgs = ((InternalEObject)source).eInverseRemove(this, CoredefPackage.NODE__OUTS, Node.class, msgs);
			if (newSource != null)
				msgs = ((InternalEObject)newSource).eInverseAdd(this, CoredefPackage.NODE__OUTS, Node.class, msgs);
			msgs = basicSetSource(newSource, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CoredefPackage.PROXY_EDGE__SOURCE, newSource, newSource));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Node getDestination() {
		if (destination != null && destination.eIsProxy()) {
			InternalEObject oldDestination = (InternalEObject)destination;
			destination = (Node)eResolveProxy(oldDestination);
			if (destination != oldDestination) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, CoredefPackage.PROXY_EDGE__DESTINATION, oldDestination, destination));
			}
		}
		return destination;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Node basicGetDestination() {
		return destination;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetDestination(Node newDestination,
			NotificationChain msgs) {
		Node oldDestination = destination;
		destination = newDestination;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, CoredefPackage.PROXY_EDGE__DESTINATION, oldDestination, newDestination);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDestination(Node newDestination) {
		if (newDestination != destination) {
			NotificationChain msgs = null;
			if (destination != null)
				msgs = ((InternalEObject)destination).eInverseRemove(this, CoredefPackage.NODE__INS, Node.class, msgs);
			if (newDestination != null)
				msgs = ((InternalEObject)newDestination).eInverseAdd(this, CoredefPackage.NODE__INS, Node.class, msgs);
			msgs = basicSetDestination(newDestination, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CoredefPackage.PROXY_EDGE__DESTINATION, newDestination, newDestination));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd,
			int featureID, NotificationChain msgs) {
		switch (featureID) {
			case CoredefPackage.PROXY_EDGE__SOURCE:
				if (source != null)
					msgs = ((InternalEObject)source).eInverseRemove(this, CoredefPackage.NODE__OUTS, Node.class, msgs);
				return basicSetSource((Node)otherEnd, msgs);
			case CoredefPackage.PROXY_EDGE__DESTINATION:
				if (destination != null)
					msgs = ((InternalEObject)destination).eInverseRemove(this, CoredefPackage.NODE__INS, Node.class, msgs);
				return basicSetDestination((Node)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd,
			int featureID, NotificationChain msgs) {
		switch (featureID) {
			case CoredefPackage.PROXY_EDGE__SOURCE:
				return basicSetSource(null, msgs);
			case CoredefPackage.PROXY_EDGE__DESTINATION:
				return basicSetDestination(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case CoredefPackage.PROXY_EDGE__PRE_CONDITIONS:
				return getPreConditions();
			case CoredefPackage.PROXY_EDGE__POST_CONDITIONS:
				return getPostConditions();
			case CoredefPackage.PROXY_EDGE__CONSTRAINTS:
				return getConstraints();
			case CoredefPackage.PROXY_EDGE__SOURCE:
				if (resolve) return getSource();
				return basicGetSource();
			case CoredefPackage.PROXY_EDGE__DESTINATION:
				if (resolve) return getDestination();
				return basicGetDestination();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case CoredefPackage.PROXY_EDGE__PRE_CONDITIONS:
				getPreConditions().clear();
				getPreConditions().addAll((Collection<? extends Condition>)newValue);
				return;
			case CoredefPackage.PROXY_EDGE__POST_CONDITIONS:
				getPostConditions().clear();
				getPostConditions().addAll((Collection<? extends Condition>)newValue);
				return;
			case CoredefPackage.PROXY_EDGE__CONSTRAINTS:
				getConstraints().clear();
				getConstraints().addAll((Collection<? extends Constraint>)newValue);
				return;
			case CoredefPackage.PROXY_EDGE__SOURCE:
				setSource((Node)newValue);
				return;
			case CoredefPackage.PROXY_EDGE__DESTINATION:
				setDestination((Node)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case CoredefPackage.PROXY_EDGE__PRE_CONDITIONS:
				getPreConditions().clear();
				return;
			case CoredefPackage.PROXY_EDGE__POST_CONDITIONS:
				getPostConditions().clear();
				return;
			case CoredefPackage.PROXY_EDGE__CONSTRAINTS:
				getConstraints().clear();
				return;
			case CoredefPackage.PROXY_EDGE__SOURCE:
				setSource((Node)null);
				return;
			case CoredefPackage.PROXY_EDGE__DESTINATION:
				setDestination((Node)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case CoredefPackage.PROXY_EDGE__PRE_CONDITIONS:
				return preConditions != null && !preConditions.isEmpty();
			case CoredefPackage.PROXY_EDGE__POST_CONDITIONS:
				return postConditions != null && !postConditions.isEmpty();
			case CoredefPackage.PROXY_EDGE__CONSTRAINTS:
				return constraints != null && !constraints.isEmpty();
			case CoredefPackage.PROXY_EDGE__SOURCE:
				return source != null;
			case CoredefPackage.PROXY_EDGE__DESTINATION:
				return destination != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass) {
		if (baseClass == ConditionableObject.class) {
			switch (derivedFeatureID) {
				case CoredefPackage.PROXY_EDGE__PRE_CONDITIONS: return CoredefPackage.CONDITIONABLE_OBJECT__PRE_CONDITIONS;
				case CoredefPackage.PROXY_EDGE__POST_CONDITIONS: return CoredefPackage.CONDITIONABLE_OBJECT__POST_CONDITIONS;
				default: return -1;
			}
		}
		if (baseClass == ConstrainedObject.class) {
			switch (derivedFeatureID) {
				case CoredefPackage.PROXY_EDGE__CONSTRAINTS: return CoredefPackage.CONSTRAINED_OBJECT__CONSTRAINTS;
				default: return -1;
			}
		}
		if (baseClass == Edge.class) {
			switch (derivedFeatureID) {
				case CoredefPackage.PROXY_EDGE__SOURCE: return CoredefPackage.EDGE__SOURCE;
				case CoredefPackage.PROXY_EDGE__DESTINATION: return CoredefPackage.EDGE__DESTINATION;
				default: return -1;
			}
		}
		return super.eBaseStructuralFeatureID(derivedFeatureID, baseClass);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eDerivedStructuralFeatureID(int baseFeatureID, Class<?> baseClass) {
		if (baseClass == ConditionableObject.class) {
			switch (baseFeatureID) {
				case CoredefPackage.CONDITIONABLE_OBJECT__PRE_CONDITIONS: return CoredefPackage.PROXY_EDGE__PRE_CONDITIONS;
				case CoredefPackage.CONDITIONABLE_OBJECT__POST_CONDITIONS: return CoredefPackage.PROXY_EDGE__POST_CONDITIONS;
				default: return -1;
			}
		}
		if (baseClass == ConstrainedObject.class) {
			switch (baseFeatureID) {
				case CoredefPackage.CONSTRAINED_OBJECT__CONSTRAINTS: return CoredefPackage.PROXY_EDGE__CONSTRAINTS;
				default: return -1;
			}
		}
		if (baseClass == Edge.class) {
			switch (baseFeatureID) {
				case CoredefPackage.EDGE__SOURCE: return CoredefPackage.PROXY_EDGE__SOURCE;
				case CoredefPackage.EDGE__DESTINATION: return CoredefPackage.PROXY_EDGE__DESTINATION;
				default: return -1;
			}
		}
		return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass);
	}

} //ProxyEdgeImpl
